package com.stk.triplecity;

import java.util.Locale;

import com.stk.triplecity.R;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Ui {

	private int posXScore;
	private int posYScore;
	private int posXScoreElement;
	private int posYScoreElement;
	private int posXCurrent;
	private int posYCurrent;
	private int posXCurrentElement;
	private int posYCurrentElement;
	private int posXStorage;
	private int posYStorage;
	private int posXStorageElement;
	private int posYStorageElement;
	private int posXExit;
	private int posYExit;
	private int posXYes;
	private int posYYes;
	private int posXNo;
	private int posYNo;
	private Bitmap score;
	private Bitmap current;
	private Bitmap storage;
	private Bitmap itemBGscore;
	private Bitmap square;
	private Bitmap exit;
	private Bitmap pause;
	private Bitmap sign;
	private Bitmap yes;
	private Bitmap no;
	private Bitmap currentStorage;
	private Bitmap arrow;
	private int posXSign;
	private int posYSign;
	private static Ui instance;

	public Ui(Panel p, int w, int h){
		int border = p.getBorder();
		int difference = w-h-border;
		if (Locale.getDefault().getLanguage().equals("es")){
			//ES
			score = BitmapFactory.decodeResource(p.getResources(), R.drawable.scorees);
			current = BitmapFactory.decodeResource(p.getResources(), R.drawable.nextes);
			storage = BitmapFactory.decodeResource(p.getResources(), R.drawable.storagees);
			itemBGscore = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(p.getResources(), R.drawable.items), difference-border, p.getTileSize(), true);
			square = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(p.getResources(), R.drawable.square), p.getTileSize(), p.getTileSize(), true);
			yes = BitmapFactory.decodeResource(p.getResources(), R.drawable.yeses);
			yes = Bitmap.createScaledBitmap(yes, (p.getTileSize()*yes.getWidth())/yes.getHeight(), p.getTileSize(), true);
			no = BitmapFactory.decodeResource(p.getResources(), R.drawable.noes);
			no = Bitmap.createScaledBitmap(no, (p.getTileSize()*no.getWidth())/no.getHeight(), p.getTileSize(), true);
			sign = BitmapFactory.decodeResource(p.getResources(), R.drawable.sign);
			exit = BitmapFactory.decodeResource(p.getResources(), R.drawable.exites);
			exit = Bitmap.createScaledBitmap(exit, (exit.getWidth() * h) / sign.getWidth(), (exit.getHeight() * h) / sign.getHeight(), true);
			pause = BitmapFactory.decodeResource(p.getResources(), R.drawable.pausees);
			pause = Bitmap.createScaledBitmap(pause, w, h, true);
			sign = Bitmap.createScaledBitmap(sign, h, h, true);
			currentStorage = BitmapFactory.decodeResource(p.getResources(), R.drawable.currentstorage);
			currentStorage = Bitmap.createScaledBitmap(currentStorage, p.getTileSize(), (p.getTileSize() * currentStorage.getHeight()) / currentStorage.getWidth(), true);
			arrow = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(p.getResources(), R.drawable.arrow), p.getTileSize(), p.getTileSize(), true);

		} else { 
			//EN
			score = BitmapFactory.decodeResource(p.getResources(), R.drawable.scoreen);
			current = BitmapFactory.decodeResource(p.getResources(), R.drawable.nexten);
			storage = BitmapFactory.decodeResource(p.getResources(), R.drawable.storageen);
			itemBGscore = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(p.getResources(), R.drawable.items), difference-border, p.getTileSize(), true);
			square = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(p.getResources(), R.drawable.square), p.getTileSize(), p.getTileSize(), true);
			yes = BitmapFactory.decodeResource(p.getResources(), R.drawable.yesen);
			yes = Bitmap.createScaledBitmap(yes, (p.getTileSize()*yes.getWidth())/yes.getHeight(), p.getTileSize(), true);
			no = BitmapFactory.decodeResource(p.getResources(), R.drawable.noen);
			no = Bitmap.createScaledBitmap(no, (p.getTileSize()*no.getWidth())/no.getHeight(), p.getTileSize(), true);
			sign = BitmapFactory.decodeResource(p.getResources(), R.drawable.sign);
			exit = BitmapFactory.decodeResource(p.getResources(), R.drawable.exiten);
			exit = Bitmap.createScaledBitmap(exit, (exit.getWidth() * h) / sign.getWidth(), (exit.getHeight() * h) / sign.getHeight(), true);
			pause = BitmapFactory.decodeResource(p.getResources(), R.drawable.pauseen);
			pause = Bitmap.createScaledBitmap(pause, w, h, true);
			sign = Bitmap.createScaledBitmap(sign, h, h, true);
			currentStorage = BitmapFactory.decodeResource(p.getResources(), R.drawable.currentstorage);
			currentStorage = Bitmap.createScaledBitmap(currentStorage, p.getTileSize(), (p.getTileSize() * currentStorage.getHeight()) / currentStorage.getWidth(), true);
			arrow = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(p.getResources(), R.drawable.arrow), p.getTileSize(), p.getTileSize(), true);

		}

		if (current.getWidth()+p.getItemBgBorder()*2 >= difference-border){
			score = Bitmap.createScaledBitmap(score, (difference-border)/2, (score.getHeight()*(difference-border)/score.getWidth())/2, true);
			current = Bitmap.createScaledBitmap(current, (difference-border)/2, (current.getHeight()*(difference-border)/current.getWidth())/2, true);
			storage = Bitmap.createScaledBitmap(storage, (difference-border)/2, (storage.getHeight()*(difference-border)/storage.getWidth())/2, true);
		}else{
			score = Bitmap.createScaledBitmap(score, (p.getTileSize()*score.getWidth()/score.getHeight())/2, (p.getTileSize())/2, true);
			current = Bitmap.createScaledBitmap(current, (p.getTileSize()*current.getWidth()/current.getHeight())/2, (p.getTileSize())/2, true);
			storage = Bitmap.createScaledBitmap(storage, (p.getTileSize()*storage.getWidth()/storage.getHeight())/2, (p.getTileSize())/2, true);
		}

		if (difference <= p.getTileSize()*2){
			posXCurrent = w-(w - h)+border;
			posXStorage = w-(w - h)+border;
			posYCurrent = border + p.getTileSize()*2;	
			posYStorage = border + p.getTileSize()*4;	


			posXCurrentElement = posXCurrent;
			posXStorageElement = posXStorage;
			posYCurrentElement = posYCurrent + current.getHeight()+ p.getItemBgBorder();
			posYStorageElement = posYStorage + storage.getHeight()+ p.getItemBgBorder();
		}else{
			posXCurrent =  w-(w - h)+border;
			posXStorage = posXCurrent + (w-h-border*2)/2;
			posYCurrent = posYStorage = border + p.getTileSize()*2;

			posXCurrentElement = posXCurrent;
			posXStorageElement = posXStorage;
			posYCurrentElement = posYCurrent + current.getHeight()+ p.getItemBgBorder();
			posYStorageElement = posYStorage + storage.getHeight()+ p.getItemBgBorder();
		}

		posXScore =  w-(w - h)+border;
		posYScore = border; 

		posXScoreElement = posXScore;
		posYScoreElement = posYScore + score.getHeight();

		posXSign = (w / 2) - (sign.getWidth()/2);
		posYSign = 0;
		posXYes = (w/2) - yes.getWidth() - border;
		posYYes = h/2;
		posXNo = (w/2) + border;
		posYNo = h/2;

		posXExit = (w / 2) - (exit.getWidth()/2);
		posYExit = h/5;
	}
	
	public static Ui getInstance(Panel p, int w, int h){
		if (instance==null){
			instance = new Ui(p, w, h);
		}
		return instance;
	}

	public int getPosXScore() {
		return posXScore;
	}

	public void setPosXScore(int posXScore) {
		this.posXScore = posXScore;
	}

	public int getPosYScore() {
		return posYScore;
	}

	public void setPosYScore(int posYScore) {
		this.posYScore = posYScore;
	}

	public int getPosXScoreElement() {
		return posXScoreElement;
	}

	public void setPosXScoreElement(int posXScoreElement) {
		this.posXScoreElement = posXScoreElement;
	}

	public int getPosYScoreElement() {
		return posYScoreElement;
	}

	public void setPosYScoreElement(int posYScoreElement) {
		this.posYScoreElement = posYScoreElement;
	}

	public int getPosXCurrent() {
		return posXCurrent;
	}

	public void setPosXCurrent(int posXNext) {
		this.posXCurrent = posXNext;
	}

	public int getPosYCurrent() {
		return posYCurrent;
	}

	public void setPosYCurrent(int posYNext) {
		this.posYCurrent = posYNext;
	}

	public int getPosXCurrentElement() {
		return posXCurrentElement;
	}

	public void setPosXCurrentElement(int posXNextElement) {
		this.posXCurrentElement = posXNextElement;
	}

	public int getPosYCurrentElement() {
		return posYCurrentElement;
	}

	public void setPosYCurrentElement(int posYNextElement) {
		this.posYCurrentElement = posYNextElement;
	}

	public int getPosXStorage() {
		return posXStorage;
	}

	public void setPosXStorage(int posXStorage) {
		this.posXStorage = posXStorage;
	}

	public int getPosYStorage() {
		return posYStorage;
	}

	public void setPosYStorage(int posYStorage) {
		this.posYStorage = posYStorage;
	}

	public int getPosXStorageElement() {
		return posXStorageElement;
	}

	public void setPosXStorageElement(int posXStorageElement) {
		this.posXStorageElement = posXStorageElement;
	}

	public int getPosYStorageElement() {
		return posYStorageElement;
	}

	public void setPosYStorageElement(int posYStorageElement) {
		this.posYStorageElement = posYStorageElement;
	}

	public Bitmap getScore() {
		return score;
	}

	public void setScore(Bitmap score) {
		this.score = score;
	}

	public Bitmap getCurrent() {
		return current;
	}

	public void setCurrent(Bitmap next) {
		this.current = next;
	}

	public Bitmap getStorage() {
		return storage;
	}

	public void setStorage(Bitmap storage) {
		this.storage = storage;
	}

	public Bitmap getItemBGscore() {
		return itemBGscore;
	}

	public void setItemBGscore(Bitmap itemBGscore) {
		this.itemBGscore = itemBGscore;
	}

	public Bitmap getSquare() {
		return square;
	}

	public void setSquare(Bitmap square) {
		this.square = square;
	}

	public int getPosXExit() {
		return posXExit;
	}

	public void setPosXExit(int posXExit) {
		this.posXExit = posXExit;
	}

	public int getPosYExit() {
		return posYExit;
	}

	public void setPosYExit(int posYExit) {
		this.posYExit = posYExit;
	}

	public int getPosXYes() {
		return posXYes;
	}

	public void setPosXYes(int posXYes) {
		this.posXYes = posXYes;
	}

	public int getPosYYes() {
		return posYYes;
	}

	public void setPosYYes(int posYYes) {
		this.posYYes = posYYes;
	}

	public int getPosXNo() {
		return posXNo;
	}

	public void setPosXNo(int posXNo) {
		this.posXNo = posXNo;
	}

	public int getPosYNo() {
		return posYNo;
	}

	public void setPosYNo(int posYNo) {
		this.posYNo = posYNo;
	}

	public Bitmap getExit() {
		return exit;
	}

	public void setExit(Bitmap exit) {
		this.exit = exit;
	}

	public Bitmap getYes() {
		return yes;
	}

	public void setYes(Bitmap yes) {
		this.yes = yes;
	}

	public Bitmap getNo() {
		return no;
	}

	public void setNo(Bitmap no) {
		this.no = no;
	}

	public Bitmap getPause() {
		return pause;
	}

	public void setPause(Bitmap pause) {
		this.pause = pause;
	}

	public Bitmap getSign() {
		return sign;
	}

	public void setSign(Bitmap sign) {
		this.sign = sign;
	}

	public int getPosXSign() {
		return posXSign;
	}

	public void setPosXSign(int posXSign) {
		this.posXSign = posXSign;
	}

	public int getPosYSign() {
		return posYSign;
	}

	public void setPosYSign(int posYSign) {
		this.posYSign = posYSign;
	}

	public Bitmap getCurrentStorage() {
		return currentStorage;
	}

	public void setCurrentStorage(Bitmap currentStorage) {
		this.currentStorage = currentStorage;
	}

	public Bitmap getArrow() {
		return arrow;
	}

	public void setArrow(Bitmap arrow) {
		this.arrow = arrow;
	}



}
